package validator

import "regexp"

type decimalType struct{}

var decimalReg = regexp.MustCompile("^(0|[1-9][0-9]*)(|\\.[0-9]+)$")

func (t *decimalType) Validate(name string, val string, required bool) (bool, string) {
	if val == "" {
		if required {
			return false, name + "不能为空"
		}
		return true, ""
	}

	if !decimalReg.MatchString(val) {
		return false, name + "应为非负的整数或小数"
	}

	return true, ""
}
